package cn.ibizlab.odoo.core.odoo_stock.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat;
import cn.ibizlab.odoo.core.odoo_stock.domain.Stock_fixed_putaway_strat;
import cn.ibizlab.odoo.core.odoo_stock.filter.Stock_fixed_putaway_stratSearchContext;
import cn.ibizlab.odoo.core.odoo_stock.service.IStock_fixed_putaway_stratService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[位置固定上架策略] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Stock_fixed_putaway_stratServiceImpl implements IStock_fixed_putaway_stratService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Istock_fixed_putaway_stratClientService stock_fixed_putaway_stratClientService;

    @Override
    public void createBatch(List<Stock_fixed_putaway_strat> stock_fixed_putaway_strats, int batchSize) {

                        //stock_fixed_putaway_stratClientService.createBatch(stock_fixed_putaway_strats,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Istock_fixed_putaway_strat clientModel = stock_fixed_putaway_stratClientService.createModel();
        clientModel.setId(id);
        stock_fixed_putaway_stratClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public Stock_fixed_putaway_strat get(Integer id) {
        Istock_fixed_putaway_strat clientModel = stock_fixed_putaway_stratClientService.createModel();
        clientModel.setId(id);
        stock_fixed_putaway_stratClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Stock_fixed_putaway_strat get(Stock_fixed_putaway_strat stock_fixed_putaway_strat) {
        Stock_fixed_putaway_strat retstock_fixed_putaway_strat = this.get(stock_fixed_putaway_strat.getId()) ;
    	BeanCopier copier=BeanCopier.create(retstock_fixed_putaway_strat.getClass(), stock_fixed_putaway_strat.getClass(), false);
        copier.copy(retstock_fixed_putaway_strat, stock_fixed_putaway_strat, null);
        return stock_fixed_putaway_strat ;
    }

    @Override
    public void updateBatch(List<Stock_fixed_putaway_strat> stock_fixed_putaway_strats, int batchSize) {

        //stock_fixed_putaway_stratClientService.updateBatch(stock_fixed_putaway_strats,batchSize) ;

    }

    @Override
    public boolean update(Stock_fixed_putaway_strat stock_fixed_putaway_strat) {
        boolean bOk = false ;
        Istock_fixed_putaway_strat clientModel = this.convert2Model(stock_fixed_putaway_strat,null);
        stock_fixed_putaway_stratClientService.update(clientModel) ;
        this.convert2Domain(clientModel,stock_fixed_putaway_strat) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //stock_fixed_putaway_stratClientService.removeBatch(stock_fixed_putaway_strats) ;

    }

    @Override
    public boolean create(Stock_fixed_putaway_strat stock_fixed_putaway_strat) {
        boolean bOk = false ;
        Istock_fixed_putaway_strat clientModel = this.convert2Model(stock_fixed_putaway_strat,null);
        stock_fixed_putaway_stratClientService.create(clientModel) ;
        this.convert2Domain(clientModel,stock_fixed_putaway_strat);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> searchDefault(Stock_fixed_putaway_stratSearchContext context) {
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据产品种类查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> selectByOdoo_category(Integer id){
        Stock_fixed_putaway_stratSearchContext context = new Stock_fixed_putaway_stratSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据产品查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> selectByOdoo_product(Integer id){
        Stock_fixed_putaway_stratSearchContext context = new Stock_fixed_putaway_stratSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据上架策略查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> selectByOdoo_putaway(Integer id){
        Stock_fixed_putaway_stratSearchContext context = new Stock_fixed_putaway_stratSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> selectByOdoo_create(Integer id){
        Stock_fixed_putaway_stratSearchContext context = new Stock_fixed_putaway_stratSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> selectByOdoo_write(Integer id){
        Stock_fixed_putaway_stratSearchContext context = new Stock_fixed_putaway_stratSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据库存位置查询
     */
    @Override
    public Page<Stock_fixed_putaway_strat> selectByOdoo_fixed_location(Integer id){
        Stock_fixed_putaway_stratSearchContext context = new Stock_fixed_putaway_stratSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_fixed_putaway_strat> list = new ArrayList<Stock_fixed_putaway_strat>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat> clientModelList = stock_fixed_putaway_stratClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_fixed_putaway_strat clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_fixed_putaway_strat>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Istock_fixed_putaway_strat convert2Model(Stock_fixed_putaway_strat domain , Istock_fixed_putaway_strat model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = stock_fixed_putaway_stratClientService.createModel() ;
        }

         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCategory_id_textDirtyFlag())
            model.setCategory_id_text(domain.getCategory_id_text());
         if(domain.getFixed_location_id_textDirtyFlag())
            model.setFixed_location_id_text(domain.getFixed_location_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getProduct_id_textDirtyFlag())
            model.setProduct_id_text(domain.getProduct_id_text());
         if(domain.getPutaway_id_textDirtyFlag())
            model.setPutaway_id_text(domain.getPutaway_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getPutaway_idDirtyFlag())
            model.setPutaway_id(domain.getPutaway_id());
         if(domain.getCategory_idDirtyFlag())
            model.setCategory_id(domain.getCategory_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getProduct_idDirtyFlag())
            model.setProduct_id(domain.getProduct_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getFixed_location_idDirtyFlag())
            model.setFixed_location_id(domain.getFixed_location_id());
        return model ;
    }

    public Stock_fixed_putaway_strat convert2Domain( Istock_fixed_putaway_strat model ,Stock_fixed_putaway_strat domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Stock_fixed_putaway_strat();
        }

        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCategory_id_textDirtyFlag())
            domain.setCategory_id_text(model.getCategory_id_text());
        if(model.getFixed_location_id_textDirtyFlag())
            domain.setFixed_location_id_text(model.getFixed_location_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getProduct_id_textDirtyFlag())
            domain.setProduct_id_text(model.getProduct_id_text());
        if(model.getPutaway_id_textDirtyFlag())
            domain.setPutaway_id_text(model.getPutaway_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getPutaway_idDirtyFlag())
            domain.setPutaway_id(model.getPutaway_id());
        if(model.getCategory_idDirtyFlag())
            domain.setCategory_id(model.getCategory_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getProduct_idDirtyFlag())
            domain.setProduct_id(model.getProduct_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getFixed_location_idDirtyFlag())
            domain.setFixed_location_id(model.getFixed_location_id());
        return domain ;
    }


}
